home *** CD-ROM | disk | FTP | other *** search
- // Dynamic link library implementation of NeuroSolutions LpCriterion component
-
- #include "NSDLL.h"
-
- /***********************************/
- /* Forward activation of component */
-
- __declspec(dllexport) NSFloat performCriterion(
- DLLData *instance, // Pointer to instance data (may be NULL)
- NSFloat *costDerivative, // Pointer to the cost derivative vector, i.e. output sensitivity
- int rows, // Number of rows of PEs in the layer
- int cols, // Number of columns of PEs in the layer
- NSFloat *output, // Pointer to the output layer of the network
- NSFloat *desired, // Pointer to the desired output vector, same length as output layer
- BOOL testing // Flag to indicate whether or not the data is for the test set
- )
- {
- int i,length=rows*cols;
- NSFloat error, cost=0.0f;
- int pConstant = getIntParameter(instance, 2, 1);
-
- for (i=0; i<length; i++) {
- error = desired[i] - output[i];
- costDerivative[i] = error*(NSFloat)fabs((NSFloat)pow((double)error, (double)pConstant-2));
- cost += (NSFloat)fabs((NSFloat)pow((double)error, (double)pConstant));
- }
- cost *= 1.0f/(NSFloat)pConstant;
- return cost;
- }
-
- /******************************************/
- /* Management of instance data (OPTIONAL) */
-
- __declspec(dllexport) DLLData *allocCriterion(
- DLLData *oldInstance, // Pointer to the last instance if reallocating
- int rows, // Number of rows of PEs in the layer
- int cols // Number of columns of PEs in the layer
- )
- {
- DLLData *instance = allocDLLInstance(oldInstance);
- setParameterName(instance, 2, 1, "p", FALSE);
- setIntParameter(instance, 2, 1, 5, FALSE);
- return instance;
- }
-
- __declspec(dllexport) void freeCriterion(DLLData *instance)
- {
- freeDLLInstance(instance);
- }
-
-